
#include <game_state/menu/menu_game_state.hpp>
#include <game_state/running/game_running.hpp>
#include <game_state/level_select/level_select.hpp>
#include <input/actions/actions.hpp>
#include <boost/bind.hpp>
#include <drawables/animation.hpp>

game_state_ptr menu_game_state::step( float delta_time ) 
{
	//BFCallback bfc = boost::bind( &menu_game_state::mainMenuCallback, this, _1, _2 );
	//menu.update( bfc, delta_time );

	//if ( next_state != nullptr )
	//{
	//	return next_state;
	//}
	//else
	//{
	//	return shared_from_this( );
	//}

	if ( m_switching )
	{
		if ( m_select_sound.GetStatus( ) == sf::Sound::Stopped )
		{
			return game_state_ptr( new level_select_state( ) );
		}
	}
	else
	{
		if ( g_user_input.getActionInput(actions::menu_select).status == keyPressed )
		{
			m_select_sound.Play( );
			m_switching = true;
		}
	}

	m_press_space->update( delta_time );

	return shared_from_this( );
}

void menu_game_state::draw()
{
	m_spritecan.draw();
	m_press_space->draw( );
	//menu.draw();
}

menu_game_state::menu_game_state()
	:		m_select_sound( *g_cache.load_buffer( "./resources/audio/menu_select.wav" ) )
{
	m_switching = false;
	m_spritecan.fill( "./resources/images/menu/background.tga", 0,0 );
	m_press_space.reset( new animation( "./resources/images/menu/press_space.anim" ) );
	m_press_space->move_to( 250.0f, 500.0f );

	//animation* anim = new animation(); anim->move_to( b2Vec2(250,450) );
	//anim->loadFromFile( "./resources/images/menu/begin.xml" );
	//drawable_ptr begin_s = drawable_ptr( anim );

	//drawable_ptr begin_u = drawable_ptr(new sprite("./resources/images/menu/begin_u.png", 250,450));
	//drawable_ptr load_s = drawable_ptr(new sprite("./resources/images/menu/load_s.png", 250,550));
	//drawable_ptr load_u = drawable_ptr(new sprite("./resources/images/menu/load_u.png", 250,550));

	//menu.addSelection( "begin", begin_s, begin_u );
	//menu.addSelection( "load",  load_s, load_u );

	//g_user_input.assignActionToKey(actions::menu_down,		sf::Key::W);
	//g_user_input.assignActionToKey(actions::menu_up,		sf::Key::S);
	g_user_input.assignActionToKey(actions::menu_select,	sf::Key::Space);

	//menu.setDecrementAction(actions::menu_down);
	//menu.setIncrementAction(actions::menu_up);
	//menu.setSelectAction(actions::menu_select);
}

//void menu_game_state::mainMenuCallback( int arrayId, std::string const& selectedName )
//{
//	if ( selectedName == "begin" || selectedName == "load" )
//	{
//		//next_state = game_state_ptr( new game_running_state( "./resources/data/level/level_1.level" ) );
//		next_state = game_state_ptr( new level_select_state( ) );
//	}
//}